#include "hiVideoApp.h"
#include "HiAutoIncrease.h"
#include "HiMapEx.h"
#include "hiVideoImage.h"
#include <map>
#include <stdio.h>

using namespace std;

static Hi::HiMapEx<long, HiVideo2Image *> shares;
static Hi::HiAutoIncrease key_proxy;

long hi_video_image_share_start(const char *rtsp_url, uint16_t port,
                                uint32_t width, uint32_t height, long flag) {
    printf("\nhi_video_image_share_start input\n\t"
           "rtsp_url:%s\n\t"
           "port:%d\n\t"
           "width:%d\n\t"
           "height:%d\n\t"
           "flag:%ld\n\n",
           rtsp_url, port, width, height, flag);
    HiVideo2Image *video2Image = new HiVideo2Image();
    bool ret = video2Image->start(rtsp_url, port, width, height, flag);
    if (!ret) {
        return HI_VIDEO_IMG_FAILED;
    }
    long key = key_proxy.get();
    shares.insert(key, video2Image);
    return true;
}

bool hi_video_image_share_stop(long id) {
    HiVideo2Image *video2Image = nullptr;
    bool ret = shares.find(id, &video2Image);
    if (!ret) {
        return false;
    }
    shares.remove(id);
    delete video2Image;
    video2Image = nullptr;
    return true;
}